package beans;

import java.io.Serializable;


/**
 * Represents a position in the board
 * @author Josep M Sobrepere
 *
 */
public class Position implements Serializable{
	/**
	 * 
	 */
	private int x;
	/**
	 * 
	 */
	private int y;
	/**
	 * @return the X coordinate
	 */
	public int getX() {
		return x;
	}
	/**
	 * @param x the X coordinate 
	 */
	public void setX(int x) {
		this.x = x;
	}
	/**
	 * @return the Y coordinate
	 */
	public int getY() {
		return y;
	}
	/**
	 * @param y the Y coordinate
	 */
	public void setY(int y) {
		this.y = y;
	}
	/**
	 * Main constructor setting the x and y coordinates
	 * @param x X coordinate
	 * @param y y coordinate
	 */
	public Position(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}
	/**
	 * Constructor equivalent to a clone method
	 * @param position position to be cloned
	 */
	public Position(Position position) {
		super();
		this.x = position.getX();
		this.y = position.getY();
	}
	/**
	 * Checks if the position is inside the allowed range on the board
	 * @return a boolean value indicating if the position is inside the allowed range
	 */
	public boolean isInRange(){
		return (this.getX()>-1 && this.getX()<8 && this.getY()>-1 && this.getY()<8);
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Position other = (Position) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Position [x=" + x + ", y=" + y + "]";
	}
	

}
